/** 	
	Description : 	Init script file, binding events to object's routine
	Author: 		Pad (Greg D)
	
*/

( function( $ ){
	
	// Binding global Nav
	// 		$('section#main div') : 	container
	//		$('nav#mainmenu ul li') :	nav
	//		$('img.nav') : 				floatNav
	var slider = new MenuSlider( $('section#main div#container'), $('.mainmenu ul'), $('img.nav') );
	
	slider.floatNav.on('click', function(){
		slider.setCoordinates( $(this).data('dir') );
		slider.fireOwnEvent();
		slider.transition();
	});
	
	slider.nav.on( "click", "li", function(){
		slider.setCoordinates( null, $(this).data('order') );
		slider.fireOwnEvent( $(this).data("ownevent") );
		slider.transition( -( $(this).data("order")* slider.articleHeight ) );
	});
	// END Binding global Nav
	// ---------------------------------------------------------------------------------------------
	
	
	// Binding Tournament Section
	//		$('article#tournament') : 		container
	//		$('div#d_history') : 			history Panel
	//		$('canvas#b_addTournament') : 	addTournament Button
	var tournament = new Tournament( $('article#tournament'), $('div#d_history'), $('canvas#b_addTournament') );
	$("body").on( "tournament/home", function(){
		console.log("Show History !!");
		tournament.animateHistory();
	});
	// END Binding tournament Section
	// ---------------------------------------------------------------------------------------------
	
	// Binding the tournament history with the template and creating the data to show
	// 		
	// Here, have to create a function which can grab the history tournament from the webSQL/ MySQL data layer
	var data = [
		{
			date: '03/05/2012',
			nbPlayers: 8,
			winnerName: 'Elportoricos'
		},
		{
			date: '10/05/2012',
			nbPlayers: 7,
			winnerName: 'Godzi'
		},
		{
			date: '17/05/2012',
			nbPlayers: 9,
			winnerName: 'Kiwi'
		}
	];
	
	var template = Handlebars.compile( $('#tpl_histTournament').html() );
	
	$('ul.tournamentHistory').show().append( template(data) );
	
	// END Binding tournament history
} )( jQuery );